package com.homegoods.classify.presenter;


import com.alibaba.fastjson.JSON;
import com.homegoods.goods.model.GoodsModel;
import com.homegoods.home.HomeApiUtils;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;

import java.util.List;


/**
 * @author QiQi
 */
public class ClassifyListFragmentPresenter extends AbstractRefreshPresenter<RefreshingView> {

    /**
     * 分类的类型
     */
    private String mSId;

    private int pos = 1;

    public ClassifyListFragmentPresenter(RefreshingView view, String sId) {
        super(view);
        this.mSId = sId;
    }


    @Override
    protected void fetchData(final boolean loadMore) {
        if (loadMore) {
            pos++;
        }
        HomeApiUtils.ComdiyList(mSId, 20, pos, subModelItem -> {
            List<GoodsModel> comdiyListModelList = JSON.parseArray(subModelItem.getItems(), GoodsModel.class);
            if (comdiyListModelList != null && comdiyListModelList.size() != 0) {
                parserData(loadMore, comdiyListModelList);
            } else {
                mView.setRefreshing(false);
            }

        }, throwable -> {

        });
    }
}

